package com.fin.zw.aiqas.util;

import org.java_websocket.WebSocket;

public class SocketClientUtils {

    public static void sendText(String url, String json) throws Exception {
        MyWebSocketClient client = new MyWebSocketClient(url);
        client.connect();
        int index = 0;
        while (!client.getReadyState().equals(WebSocket.READYSTATE.OPEN)) {
            System.out.println("webSocket链接还没有打开");
            index++;
            Thread.currentThread().sleep(1000);
            if (index == 30) {
                System.out.println("webSocket客户端链接超时");
                client.close();
                break;
            }
        }
        if (client.getReadyState().equals(WebSocket.READYSTATE.OPEN)) {
            System.out.println("webSocket客户端链接成功");
            client.send(json);
        }
    }


    public static void main(String[] args) throws Exception {
        sendText("ws://114.116.39.18:8999", "测试数据");
    }
}
